<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header">

</head>
<style type="text/css">
	.bootstrap-tree-table .treetable-tbody td {
		border: 0 !important;
		border-left: 0px solid #e7eaec !important;
		border-bottom: 1px solid #e7eaec!important;
		overflow: visible;
		white-space: nowrap;
		text-overflow: clip;
	}

	.bootstrap-tree-table .treetable-table tbody {
		display: block;
		height: auto;
		overflow-y: visible;
	}
</style>
<body class="gray-bg">
<div class="row">
    <div class="col-sm-12 select-info">
        <form id="user-form">
            <input type="hidden" id="apiProjectnameId" name="apiProjectnameId">
            <input type="hidden" id="parentId" name="parentId">
            <div class="select-list">
                <ul>
                    <li>
                        项目名称：<input type="text" name="projectname"/>
                    </li>
                    <li>
                        项目描述：<input type="text" name="description"/>
                    </li>
                    <li>
                        错误组码：<input type="text" name="errorGroup"/>
                    </li>
                    <li>
                        &nbsp;&nbsp;&nbsp;&nbsp;创建人：<input type="text" name="createBy"/>
                    </li>
                    <li class="select-time">
                        <label>创建时间： </label>
                        <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                        <span>-</span>
                        <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="container-div">
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add(0)" shiro:hasPermission="module:project:add">
				<i class="fa fa-plus"></i> 新增
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped table-responsive">
		<!--<div class="col-sm-12 select-table table-striped">-->
			<!--<table id="bootstrap-table" data-mobile-responsive="true" class="table table-bordered" style="white-space:nowrap;"></table>-->
			<table id="bootstrap-table" data-mobile-responsive="true" class="table table-bordered" style="white-space:nowrap;"></table>
		</div>
    </div>
</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('module:project:add')}]];
        var editFlag = [[${@permission.hasPermi('module:project:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:project:remove')}]];
		//var datas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "module/project";

        $(function() {
            var options = {
                id: "apiProjectnameId",
                parentId: "parentId",
                //url: prefix + "/list",
                url: prefix + "/listtree",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                expandAll: false,
                modalName: "接口项目",
                sortable: true,                                     // 是否启用排序
                sortStable: true,                                   // 设置为 true 将获得稳定的排序
                sortName: "orderNum",                                // 排序列名称
                sortOrder: "asc",                              // 排序方式  asc 或者 desc
                columns: [
				{
					field : 'description',
					title : '项目描述'
					// ,width: "200px"

				},{
					field : 'apiProjectnameId', 
					title : '项目ID' ,
		            align: "center"

				},
				{
					field : 'projectname', 
					title : '项目名称' ,
		            align: "center"
				},

				{
					// field : 'apiDomainId',
					title : '域名' ,
		            align: "center",
                    width: '300px',
                    formatter: function(value, row, index) {
					    if(row.domain==undefined||row.domain==''||row.domain==null){
                            return "";
						}
                        return row.domain.named+':'+row.domain.port+'['+row.domain.description+']';
                    }
				},
                {
                    field : 'errorGroup',
                    title : '错误组' ,
                    align: "center"
                },
				// {
				// 	field : 'remark',
				// 	title : '备注' ,
		         //    align: "center"
				// },
		        {
		            field: 'orderNum',
		            title: '排序',
		            align: "center"
		        },
				// {
				// 	field : 'createBy',
				// 	title : '创建者',
		         //    align: "center"
				// },
				// {
				// 	field : 'createTime',
				// 	title : '创建时间',
		         //    align: "center"
                 //    ,width: '180px'
				// },
				{
					field : 'updateBy',
					title : '更新者',
		            align: "center"
				},
				{
					field : 'updateTime',
					title : '更新时间',
		            align: "center"
                    ,width: '180px'
				},
		        {
		            title: '操作',
		            align: 'center',
                    // width: '180px',
		            formatter: function(value, row, index) {
		            	var actions = [];

                        // if (!hasChilds) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.apiProjectnameId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="#" onclick="add(\'' + row.apiProjectnameId + '\')"><i class="fa fa-plus">新增</i></a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.apiProjectnameId + '\')"><i class="fa fa-remove">删除</i></a>');
                            return actions.join('');
                        // } else {
                        //     actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.apiProjectnameId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //     actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="#" onclick="add(\'' + row.apiProjectnameId + '\')"><i class="fa fa-plus">新增</i></a> ');
                        //     actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" disabled="true"><i class="fa fa-remove"></i>删除</a>');
                        //     return actions.join('');
                        // }
		            }
		        }]
            };
            //$.table.init(options);
		    $.treeTable.init(options);

        });

        function add(id) {
            var stateObject = {};
            var title = "接口模块";
            var newUrl = prefix+"/uniqueid/"+id;
            window.history.pushState(stateObject,title,newUrl);
            $.operate.add(id);
        }

        function edit(id) {
            var stateObject = {};
            var title = "接口模块";
            var newUrl = prefix+"/uniqueid/"+id;
            window.history.pushState(stateObject,title,newUrl);
            $.operate.edit(id);

        }

        function remove(id) {
            var hasChilds=true;
            $.ajax({
                async:false,
                type : 'post',
                url: prefix + "/hasChilds?apiProjectnameId=" + id,
                success : function(result) {
                    console.log("result=",result);
                    if (!result) {
                        hasChilds=false;
                    }
                }
            });
            if(hasChilds){
                $.modal.alertError("该条记录包含关联子级,不允许删除");
                return;
            }

            $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function() {
                $.ajax({
                    type : 'post',
                    url: prefix + "/remove/" + id,
                    success : function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess(result.msg);
                            $.treeTable.refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }
                    }
                });
            });
        }
    </script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var id = [[${uniqueid}]];
    var ancestors=[[${ancestors}]];
    /*]]>*/
    $(document).ready(function () {
        if(id!=undefined){

            function positioningNode(){
                // console.log(zTree_Menu);
                setTimeout(function () {
                    console.log("uniqueid="+id);
                    console.log("ancestors-",ancestors);

                    for (var i = 0; i <ancestors.length; i++) {
                        $._treeTable.bootstrapTreeTable('expandNode', {id:ancestors[i],options:$.table._option});
                        console.log(ancestors[i]);
                    }

                    console.log($.treeTable);
                    console.log("$.table._option=",$.table._option);
                    $._treeTable.bootstrapTreeTable('expandNode', {id:id,options:$.table._option});

                }, 1000);
            }

            positioningNode();
        }
    });



</script>
</body>
</html>